Assignment 1: Pixel Regression.

Can we recover an image by learning a deep regression map from pixels $(x,y)$ to colors $(r,g,b)$?

Our target image will be Mona Lisa:


In [7]:
import matplotlib.image as mpimg
import matplotlib.pylab as plt
import numpy as np
%matplotlib inline

im = mpimg.imread("data/monalisa.jpg")

plt.imshow(im)
plt.show()
im.shape


Out[7]:
(199, 153, 3)

Ourt training dataset will be composed of pixels locatiions and input and pixel values as output:


In [8]:
X_train = []
Y_train = []
for i in range(im.shape[0]):
    for j in range(im.shape[1]):
        X_train.append([float(i),float(j)])
        Y_train.append(im[i][j])
        
X_train = np.array(X_train)
Y_train = np.array(Y_train)
print 'Samples:', X_train.shape[0]
print '(x,y):', X_train[0],'\n', '(r,g,b):',Y_train[0]


Samples: 30447
(x,y): [ 0.  0.] 
(r,g,b): [ 85 105 116]

Our objective is to train a deep MLP that is able to reconstruct the image:


In [ ]:
import keras
from keras.models import Sequential
from keras.layers.core import Dense, Activation, Dropout

# your model here
# hints: k*10^2 neurons per layer + good initialization + deep network (>2 layers)

In [ ]:
# use this cell to find the best model architecture

model.fit(X_train, Y_train, nb_epoch=1, shuffle=True, verbose=1, batch_size=10)
Y = model.predict(X_train, batch_size=10000)
k = 0
im_out = im[:]
for i in range(im.shape[0]):
    for j in range(im.shape[1]):
        im_out[i,j]= Y[k]
        k += 1
        
plt.imshow(im_out)
plt.show()